using System;
namespace WebApplication14
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SubmitButton_Click(object sender, EventArgs e)
{
try
{
int number = int.Parse(InputTextBox.Text);
if (number < 0)
{
throw new NegativeNumberException("Negative numbers are not
allowed.");
}
ResultLabel.Text = $"You entered: {number}";
}
catch (NegativeNumberException ex)
{
ResultLabel.Text = ex.Message;
ResultLabel.ForeColor = System.Drawing.Color.Red;
}
catch (FormatException)
{
ResultLabel.Text = "Please enter a valid integer.";
ResultLabel.ForeColor = System.Drawing.Color.Red;
}
catch (Exception ex)
{
ResultLabel.Text = $"An error occurred: {ex.Message}";
ResultLabel.ForeColor = System.Drawing.Color.Red;
}
}
}
// User-defined exception
public class NegativeNumberException : Exception
{
public NegativeNumberException(string message) : base(message)
{
}
}
}